﻿@{
    ViewBag.Title = "Detail";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}

<script src="~/Content/adminDefault/js/default.js"></script>
<script>
    var SPLId = request('SPLId');
    var SPIId = request('SPIId');
    var Name = decodeURI(request('Name'));
    var PName = decodeURI(request('PName'));
    var type = request('type');
    var StartTime = request('StartTime');
    var AddDate = request('AddDate');
    var height = 0;
    $(function () {
        InitialPage();
        GetGrid();
    })
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth(($('.gridPanel').width() * 0.6));
                $("#gridTable").setGridHeight($(window).height() - 175.5);
            }, 200);
            e.stopPropagation();
        });
        $("#Name").text(Name);
        $("#PName").text(PName);
        $.ajax({
            type: "GET",
            dataType: "json",
            url: "../../PropertyManage/SecurityPatrol/GetItemEntity?keyValue=" + SPIId,
            success: function (data) {
                $("#ItemName").text(data.Name);
                switch (data.Unit) {
                    case 0: $("#Frequency").text(data.UnitNum + "天" + data.Frequency + "次"); break;
                    case 1: $("#Frequency").text(data.UnitNum + "周" + data.Frequency + "次"); break;
                    case 2: $("#Frequency").text(data.UnitNum + "月" + data.Frequency + "次"); break;
                    case 3: $("#Frequency").text(data.UnitNum + "季" + data.Frequency + "次"); break;
                    case 4: $("#Frequency").text(data.UnitNum + "年" + data.Frequency + "次"); break;
                }
            }
        });
    }
    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        $gridTable.jqGrid({
            url: "../../PropertyManage/SecurityPatrol/GetResultList",
            postData: { StartTime: StartTime, AddDate: AddDate, SPLId: SPLId, type: type },
            datatype: "json",
            height: $(window).height() - 175.5,
            autowidth: true,
            colModel: [
                { label: "主键", name: "SPRId", index: "SPRId", hidden: true },
                { label: "开始时间", name: "StatrtDate", index: "StatrtDate", width: 150, align: "center" },
                { label: "结束时间", name: "EndDate", index: "EndDate", width: 150, align: "center" },
                { label: "执行人", name: "ExecManName", index: "ExecManName", width: 100, align: "center" },
                {
                    label: "执行状态", name: "Status", index: "Status", width: 100, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        switch (cellvalue) {
                            case 0: return "未完成";
                            case 1: return "已完成";
                            case 2: return "异常完成";
                            case 3: return "异常终止";
                        }
                    }
                },
                { label: "备注", name: "Date", index: "Date", width: 150, align: "center" },
            ],
            viewrecords: true,
            rowNum: 100,
            rowList: [100, 200, 300],
            pager: "#gridPager",
            sortname: 'StatrtDate',
            sortorder: 'desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function (rowid) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
                $('#gridTable1').GridUnload();
                Detail(rowid);
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
    }

    function Detail(rowid) {
        var obj = $("#gridTable").jqGrid('getRowData', rowid);
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable1');
        $gridTable.jqGrid({
            url: "../../PropertyManage/SecurityPatrol/GetResultDatile",
            postData: { SPRId: obj.SPRId, SPLId: SPLId },
            datatype: "json",
            height: $(window).height() - 175.5,
            autowidth: true,
            colModel: [
                { label: "结果记录id", name: "sprid", index: "sprid", hidden: true },
                { label: "明细id", name: "splid", index: "splid", hidden: true },
                 { label: "点Id", name: "pstructid", index: "pstructid", hidden: true },
                   { label: "有无附件标志", name: "puctureflag", index: "puctureflag", hidden: true },
                //{ label: "序号", name: "sort", index: "sort", width: 50, align: "center" },
                {
                    label: " ", name: "",  width: 50, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        return rowObject.puctureflag == 1 ? "<i class='fa fa-image'></i>" : "";
                    }
                },
                { label: "巡检点名称", name: "name", index: "name", width: 120, align: "center" },
                { label: "巡检点位置", name: "othercode", index: "othercode", width: 150, align: "center" },
                //{ label: "巡检点位置", name: "psallname", index: "psallname", width: 150, align: "center" },
                { label: "巡检时间", name: "execdate", index: "execdate", width: 150, align: "center" },
                {
                    label: "状态", name: "execstate", index: "execstate", width: 80, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        switch (cellvalue) {
                            case 1: return "已完成";
                            case 2: return "跳过";
                            case 3: return "异常终止";
                        }
                    }
                },
                { label: "备注", name: "execmemo", index: "execmemo", width: 150, align: "center" },
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager1",
            sortname: 'sort',
            sortorder: 'asc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function (rowid) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
                //Detail(rowid);
            },
            ondblClickRow:function(rowid){
                Content(rowid);
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
    }

    function Content(rowid) {
        var obj = $("#gridTable1").jqGrid('getRowData', rowid);
        
        dialogOpen({
            id: "Form",
            title: "巡更点内容",
            url: '../../PropertyManage/SecurityPatrol/ContentDetail?SPRId=' + obj.sprid + '&SPLId=' + obj.splid + '&PStructId=' + obj.pstructid + '&PictureFlag=' + obj.puctureflag,
            width: "800px",
            height: "600px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    }
</script>


    <div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
        <div class="ui-layout-center">
            <div class="center-Panel">
                <div class="panel-Title">巡更线路明细</div>
                <div class="titlePanel">
                    <div class="title-search">
                        <table id="queryCondition">
                            <tr style="padding-left: 10px;">
                                <td>巡更项目：</td>
                                <td id="ItemName"></td>
                                <td style="text-align: center; padding-left: 20px;">巡更路线：</td>
                                <td id="Name"></td>
                                <td style="text-align: center; padding-left: 20px;">楼盘名称：</td>
                                <td id="PName"></td>
                                <td style="padding-left: 20px;">标准频次：</td>
                                <td id="Frequency"></td>
                            </tr>
                        </table>
                    </div>
                    <div class="toolbar">
                        <div class="btn-group">
                            <a id="lr-replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                        </div>
                    </div>
                    <script>$('.toolbar').authorizeButton()</script>
                </div>
                <div class="gridPanel" style="width: 100%; border-top: 1px solid #CCC;">
                    <table style="width:100%;">
                        <tr style="width:100%;">
                            <td style="width:49%;padding-top:10px;border-right:1px solid #CCC;" valign="top">
                                <table id="gridTable"></table>
                                <div id="gridPager"></div>
                            </td>
                            <td style="width: 0.2%; background:gray;"></td>
                            <td style="width: 50%; padding-top: 10px;" valign="top">
                                <table id="gridTable1"></table>
                                <div id="gridPager1"></div>
                            </td>
                        </tr>
                    </table>

                </div>
            </div>
        </div>
    </div>
